﻿using System;
using System.Text.RegularExpressions;

namespace Confessor
{
    class xRegEx
    {
        /// <summary>
        /// RegEx testing method which returns a bool on whether it matched or not.  int is the case number you want to call for regex.
        /// </summary>
        /// <param name="i">Case 0 = IP, Case 1 = Letters, Case 2 = Email Addy, Case 3 = Windows Hostname, Case 4 = Initial IP Check</param>
        /// <param name="s"></param>
        /// <returns></returns>
        public bool RegExTest(int i, string s)
        {
            bool status = false;
            Regex regExIP = new Regex(@"\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b");
            Regex regExLetter = new Regex(@"([A-Za-z])");
            Regex regExEmail = new Regex(@"(\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})");
            Regex regExWindowsHostname = new Regex(@"(^[a-zA-Z0-9]+)");
            Regex regIpInitialCheck = new Regex(@"(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})");
            Regex regEx = new Regex("");

            switch (i)
            {
                case 0: // Match IP
                    regEx = regExIP;
                    break;
                case 1: // Letter
                    regEx = regExLetter;
                    break;
                case 2: // Email
                    regEx = regExEmail;
                    break;
                case 3: // Windows Hostname
                    regEx = regExWindowsHostname;
                    break;
                case 4: // Check to see if it looks like a IP address.
                    regEx = regIpInitialCheck;
                    break;
                default:
                    break;
            }
                
            if (regEx.IsMatch(s))
            {
                status = true;
            }
            return status;
        }
    }
}
